package c.j.a.e;

import java.io.IOException;
import java.security.MessageDigest;

/* compiled from: TTMd5 */
public class b {
    public static final char[] a = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    /* compiled from: TTMd5 */
    public static class b {
        public int a;
        public int b;
        public int c;
        public long d;
        public String e;

        public b(a aVar) {
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x004b A:{Catch:{ all -> 0x00f7, all -> 0x00fd }} */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x0070 A:{Catch:{ all -> 0x00f7, all -> 0x00fd }} */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x008c A:{LOOP_END, LOOP:1: B:21:0x008a->B:22:0x008c, Catch:{ all -> 0x00f7, all -> 0x00fd }} */
    public static java.lang.String a(java.io.File r22, int r23, long r24) throws java.lang.Exception {
        /*
        r0 = r23;
        r7 = new c.j.a.e.a;
        r1 = r22;
        r7.m2482init(r1);
        r1 = "MD5";
        r8 = java.security.MessageDigest.getInstance(r1);
        if (r8 != 0) goto L_0x0015;
    L_0x0011:
        r0 = "";
        goto L_0x00f6;
    L_0x0015:
        r1 = r7.a;	 Catch:{ all -> 0x00f7 }
        r9 = r1.length();	 Catch:{ all -> 0x00f7 }
        r11 = 1;
        if (r0 <= 0) goto L_0x0037;
    L_0x001e:
        r1 = 0;
        r3 = (r24 > r1 ? 1 : (r24 == r1 ? 0 : -1));
        if (r3 <= 0) goto L_0x0037;
    L_0x0024:
        r1 = (long) r0;	 Catch:{ all -> 0x00f7 }
        r1 = r1 * r24;
        r3 = 8;
        r3 = r3 * r9;
        r5 = 10;
        r3 = r3 / r5;
        r5 = (r1 > r3 ? 1 : (r1 == r3 ? 0 : -1));
        if (r5 <= 0) goto L_0x0033;
    L_0x0032:
        goto L_0x0037;
    L_0x0033:
        r13 = r24;
        r12 = r0;
        goto L_0x0039;
    L_0x0037:
        r13 = r9;
        r12 = 1;
    L_0x0039:
        r0 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
        r15 = new byte[r0];	 Catch:{ all -> 0x00f7 }
        r16 = 0;
        r0 = r7;
        r1 = r8;
        r2 = r15;
        r3 = r16;
        r5 = r13;
        e(r0, r1, r2, r3, r5);	 Catch:{ all -> 0x00f7 }
        r0 = 2;
        if (r12 <= r0) goto L_0x006e;
    L_0x004b:
        r0 = (long) r12;	 Catch:{ all -> 0x00f7 }
        r0 = r0 * r13;
        r0 = r9 - r0;
        r5 = r12 + -1;
        r2 = (long) r5;	 Catch:{ all -> 0x00f7 }
        r18 = r0 / r2;
        r6 = 1;
    L_0x0056:
        if (r6 >= r5) goto L_0x006e;
    L_0x0058:
        r0 = r13 + r18;
        r16 = r0 + r16;
        r0 = r7;
        r1 = r8;
        r2 = r15;
        r3 = r16;
        r20 = r5;
        r21 = r6;
        r5 = r13;
        e(r0, r1, r2, r3, r5);	 Catch:{ all -> 0x00f7 }
        r6 = r21 + 1;
        r5 = r20;
        goto L_0x0056;
    L_0x006e:
        if (r12 <= r11) goto L_0x0079;
    L_0x0070:
        r3 = r9 - r13;
        r0 = r7;
        r1 = r8;
        r2 = r15;
        r5 = r13;
        e(r0, r1, r2, r3, r5);	 Catch:{ all -> 0x00f7 }
    L_0x0079:
        r0 = r8.digest();	 Catch:{ all -> 0x00f7 }
        r1 = "bytes is null";
        java.util.Objects.requireNonNull(r0, r1);	 Catch:{ all -> 0x00f7 }
        r1 = r0.length;	 Catch:{ all -> 0x00f7 }
        r2 = r1 * 2;
        r3 = new char[r2];	 Catch:{ all -> 0x00f7 }
        r4 = 0;
        r5 = 0;
        r6 = 0;
    L_0x008a:
        if (r5 >= r1) goto L_0x00a7;
    L_0x008c:
        r8 = r5 + 0;
        r8 = r0[r8];	 Catch:{ all -> 0x00f7 }
        r8 = r8 & 255;
        r15 = r6 + 1;
        r16 = a;	 Catch:{ all -> 0x00f7 }
        r17 = r8 >> 4;
        r17 = r16[r17];	 Catch:{ all -> 0x00f7 }
        r3[r6] = r17;	 Catch:{ all -> 0x00f7 }
        r6 = r15 + 1;
        r8 = r8 & 15;
        r8 = r16[r8];	 Catch:{ all -> 0x00f7 }
        r3[r15] = r8;	 Catch:{ all -> 0x00f7 }
        r5 = r5 + 1;
        goto L_0x008a;
    L_0x00a7:
        r0 = new java.lang.String;	 Catch:{ all -> 0x00f7 }
        r0.<init>(r3, r4, r2);	 Catch:{ all -> 0x00f7 }
        if (r12 != r11) goto L_0x00b3;
    L_0x00ae:
        r1 = (r13 > r9 ? 1 : (r13 == r9 ? 0 : -1));
        if (r1 != 0) goto L_0x00b3;
    L_0x00b2:
        goto L_0x00f1;
    L_0x00b3:
        r1 = new java.lang.StringBuilder;	 Catch:{ all -> 0x00f7 }
        r1.<init>();	 Catch:{ all -> 0x00f7 }
        r2 = new java.lang.StringBuilder;	 Catch:{ all -> 0x00f7 }
        r2.<init>();	 Catch:{ all -> 0x00f7 }
        r3 = "ttmd5:1:1:";
        r2.append(r3);	 Catch:{ all -> 0x00f7 }
        r3 = (long) r12;	 Catch:{ all -> 0x00f7 }
        r5 = 4;
        r3 = r3 << r5;
        r8 = 31;
        r3 = r3 + r8;
        r3 = java.lang.Long.toHexString(r3);	 Catch:{ all -> 0x00f7 }
        r2.append(r3);	 Catch:{ all -> 0x00f7 }
        r3 = "g";
        r2.append(r3);	 Catch:{ all -> 0x00f7 }
        r3 = r13 << r5;
        r3 = r3 + r8;
        r3 = java.lang.Long.toHexString(r3);	 Catch:{ all -> 0x00f7 }
        r2.append(r3);	 Catch:{ all -> 0x00f7 }
        r2 = r2.toString();	 Catch:{ all -> 0x00f7 }
        r1.append(r2);	 Catch:{ all -> 0x00f7 }
        r2 = ";";
        r1.append(r2);	 Catch:{ all -> 0x00f7 }
        r1.append(r0);	 Catch:{ all -> 0x00f7 }
        r0 = r1.toString();	 Catch:{ all -> 0x00f7 }
    L_0x00f1:
        r1 = r7.a;	 Catch:{ all -> 0x00f6 }
        r1.close();	 Catch:{ all -> 0x00f6 }
    L_0x00f6:
        return r0;
    L_0x00f7:
        r0 = move-exception;
        r1 = r7.a;	 Catch:{ all -> 0x00fd }
        r1.close();	 Catch:{ all -> 0x00fd }
    L_0x00fd:
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.e.b.a(java.io.File, int, long):java.lang.String");
    }

    /* JADX WARNING: Removed duplicated region for block: B:52:0x0074 A:{RETURN} */
    public static int b(java.lang.String r7, java.io.File r8) {
        /*
        if (r7 == 0) goto L_0x007e;
    L_0x0002:
        r0 = r7.length();
        if (r0 != 0) goto L_0x000a;
    L_0x0008:
        goto L_0x007e;
    L_0x000a:
        if (r8 == 0) goto L_0x007c;
    L_0x000c:
        r0 = r8.exists();	 Catch:{ all -> 0x0079 }
        if (r0 != 0) goto L_0x0014;
    L_0x0012:
        goto L_0x007c;
    L_0x0014:
        r0 = -1;
        r1 = -1;
        r3 = d(r7);	 Catch:{ all -> 0x0077 }
        r4 = 1;
        if (r3 == 0) goto L_0x0028;
    L_0x001e:
        r0 = r3.a;	 Catch:{ all -> 0x0079 }
        if (r0 <= r4) goto L_0x0024;
    L_0x0022:
        r7 = 3;
        return r7;
    L_0x0024:
        r0 = r3.c;	 Catch:{ all -> 0x0079 }
        r1 = r3.d;	 Catch:{ all -> 0x0079 }
    L_0x0028:
        r5 = 0;
        r8 = a(r8, r0, r1);	 Catch:{ all -> 0x002e }
        goto L_0x0033;
    L_0x002e:
        r8 = move-exception;
        r8.printStackTrace();	 Catch:{ all -> 0x0079 }
        r8 = r5;
    L_0x0033:
        if (r8 == 0) goto L_0x0075;
    L_0x0035:
        r0 = r8.length();	 Catch:{ all -> 0x0079 }
        if (r0 != 0) goto L_0x003c;
    L_0x003b:
        goto L_0x0075;
    L_0x003c:
        r0 = 0;
        if (r3 == 0) goto L_0x006d;
    L_0x003f:
        r1 = r3.a;	 Catch:{ all -> 0x0079 }
        if (r1 != r4) goto L_0x0048;
    L_0x0043:
        r1 = r3.b;	 Catch:{ all -> 0x0079 }
        if (r1 != r4) goto L_0x0048;
    L_0x0047:
        goto L_0x006d;
    L_0x0048:
        r7 = r3.e;	 Catch:{ all -> 0x0079 }
        if (r7 == 0) goto L_0x0074;
    L_0x004c:
        r5 = d(r8);	 Catch:{ all -> 0x0051 }
        goto L_0x0052;
    L_0x0052:
        if (r5 == 0) goto L_0x0074;
    L_0x0054:
        r7 = r3.c;	 Catch:{ all -> 0x0079 }
        r8 = r5.c;	 Catch:{ all -> 0x0079 }
        if (r7 != r8) goto L_0x0074;
    L_0x005a:
        r7 = r3.d;	 Catch:{ all -> 0x0079 }
        r1 = r5.d;	 Catch:{ all -> 0x0079 }
        r6 = (r7 > r1 ? 1 : (r7 == r1 ? 0 : -1));
        if (r6 != 0) goto L_0x0074;
    L_0x0062:
        r7 = r3.e;	 Catch:{ all -> 0x0079 }
        r8 = r5.e;	 Catch:{ all -> 0x0079 }
        r7 = r7.equals(r8);	 Catch:{ all -> 0x0079 }
        if (r7 == 0) goto L_0x0074;
    L_0x006c:
        return r0;
    L_0x006d:
        r7 = r8.equals(r7);	 Catch:{ all -> 0x0079 }
        if (r7 == 0) goto L_0x0074;
    L_0x0073:
        return r0;
    L_0x0074:
        return r4;
    L_0x0075:
        r7 = 6;
        return r7;
    L_0x0077:
        r7 = 4;
        return r7;
    L_0x0079:
        r7 = 99;
        return r7;
    L_0x007c:
        r7 = 5;
        return r7;
    L_0x007e:
        r7 = 2;
        return r7;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.e.b.b(java.lang.String, java.io.File):int");
    }

    public static long c(String str) throws RuntimeException {
        try {
            return (Long.parseLong(str, 16) - 31) >> 4;
        } catch (Throwable unused) {
            RuntimeException runtimeException = new RuntimeException(c.b.a.a.a.D("ttmd5 decryptNum error, num = ", str));
        }
    }

    public static b d(String str) throws Exception {
        if (!str.startsWith("ttmd5:")) {
            return null;
        }
        String[] split = str.split(";");
        String[] split2 = split[0].split(":");
        b bVar = new b(null);
        int parseInt = Integer.parseInt(split2[1]);
        bVar.a = parseInt;
        if (parseInt > 1) {
            return bVar;
        }
        bVar.b = Integer.parseInt(split2[2]);
        split2 = split2[3].split("g");
        bVar.c = (int) c(split2[0]);
        bVar.d = c(split2[1]);
        bVar.e = split[1];
        return bVar;
    }

    public static void e(a aVar, MessageDigest messageDigest, byte[] bArr, long j, long j2) throws IOException {
        aVar.a.seek(j);
        j = 0;
        while (j < j2) {
            int read = aVar.a.read(bArr, 0, (int) Math.min(j2 - j, (long) bArr.length));
            if (read > 0) {
                messageDigest.update(bArr, 0, read);
                j += (long) read;
            } else {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("updateSample unexpected readCount <= 0, readCount = ");
                stringBuilder.append(read);
                stringBuilder.append(", readTotalCount = ");
                stringBuilder.append(j);
                stringBuilder.append(", sampleSize = ");
                stringBuilder.append(j2);
                throw new IOException(stringBuilder.toString());
            }
        }
    }
}
